import api from './fetch/api.js'

const actions = {
    /**
     * 获取登录信息actions
     * @param {*} params username password type 1学生 2教职工
     */
    userlogin({ commit }, params) {
        console.log('进入获取登录信息actions')
        return new Promise((resolve, reject) => {
            api.minePostMsgApi('http://10.20.5.7:9080' + '/itfer/rest/user/login', params)
                .then(res => {
                    resolve(res)
                })
        })
    },
    /**
     * 确认用户信息是否加载
     */
    isUserInfo({ commit, state }) {
        return new Promise((resolve, reject) => {
            let isu = setInterval(() => {
                if (state.userInfo) {
                    clearInterval(isu)
                    resolve()
                }
            }, 100)
        })
    },
    async saveUserInfo({ commit, state }, params) {
        return await api.minePostMsgApi(`${state.Host}/itfer-zbdk/rest/user/saveUserInfo`, params)
    },
    /**
     * 判断时间是否可以设置
     * day 时间
     * type 0 上午 1 下午
     */
    async checkTime({ commit, state }, params) {
        return await api.minePostMsgApi(`${state.Host}/itfer-zbdk/rest/worker/checkTime`, params)
    },
    /**
     * 获取设置时间时的规定时间
     * @param {*} day 时间
     */
    async getTimeList({ commit, state }, params) {
        return await api.minePostMsgApi(`${state.Host}/itfer-zbdk/rest/worker/getTimeList`, params)
    },
    /**
     * 修改签到计划
     */
    async changePlan({ commit, state }, params) {
        return await api.minePostMsgApi(`${state.Host}/itfer-zbdk/rest/worker/changePlan`, params)
    },
    /**
     * 发布打卡计划
     */
    async savePlan({ commit, state }, params) {
        return await api.minePostMsgApi(`${state.Host}/itfer-zbdk/rest/worker/savePlan`, params)
    },
    /**
     * 获取学校列表
     */
    async getSchoolList({ commit, state }, params) {
        return await api.mineBaseMsgApi(`${state.Host}/itfer-zbdk/rest/worker/getSchoolList`)
    },
    /**
     * 获取周计划
     */
    async getWeekPlan({commit, state}, params) {
        return await api.mineBaseMsgApi(`${state.Host}/itfer-zbdk/rest/worker/getWeekPlan/${params.userID}/${params.XN}/${params.XQ}/${params.ZC}/${params.flag}`)
    },
    /**
     * 获取当前周
     */
    async getSchoolWeek({commit, state}, params) {
        return await api.mineBaseMsgApi(`${state.Host}/itfer-zbdk/rest/worker/getSchoolWeek`)
    },
    /**
     * 删除计划
     */
    async deletePlan({commit, state}, params) {
        return await api.mineBaseMsgApi(`${state.Host}/itfer-zbdk/rest/worker/deletePlan/${params.planId}/${params.userId}`)
    },
    /**
     * 保存备注
     */
    async remarkDay({commit, state}, params) {
        return await api.minePostMsgApi(`${state.Host}/itfer-zbdk/rest/worker/remarkDay`, params)
    },
    /**
     * 获取教学周
     */
    async getSchoolWeekList({commit, state}, params) {
        return await api.mineBaseMsgApi(`${state.Host}/itfer-zbdk/rest/worker/getSchoolWeekList`)
    },
    /**
     * 获取楼栋
    */
    async getBuildingList({commit, state}, params) {
        return await api.mineBaseMsgApi(`${state.Host}/itfer-zbdk/rest/worker/getBuildingList/${params.REGION_ID}`)
    },
    /**
     * 一键设置剩余打卡计划
    */
    async setRestOfWeekPlan({commit, state}, params) {
        return await api.minePostMsgApi(`${state.Host}/itfer-zbdk/rest/worker/copyPlan`, params)
    },
    /**
     * 获取打卡计划
     */
    async getNextPlan({commit, state}, params) {
        return await api.mineBaseMsgApi(`${state.Host}/itfer-zbdk/rest/worker/getNextPlan/` + params.userId)
    },
    /**
     * 开始打卡
     */
    async startSign({commit, state}, params) {
        return await api.minePostMsgApi(`${state.Host}/itfer-zbdk/rest/worker/startSign`, params)
    },
    /**
     * 结束打卡
     */
    async endSign({commit, state}, params) {
        return await api.minePostMsgApi(`${state.Host}/itfer-zbdk/rest/worker/endSign`, params)
    },
    /**
     * 获取是否在校内打卡
     */
    async getCheckInSchool({commit, state}, params) {
        return await api.minePostMsgApi(`${state.Host}/itfer-zbdk/rest/worker/checkInSchool`, params)
    },
    /**
     * 获取管理员列表
     */
    async getCountSignList({commit, state}, params) {
        return await api.mineBaseMsgApi(`${state.Host}/itfer-zbdk/rest/admin/getCountSignList/` + params.XN + '/' + params.XQ + '/' + params.ZC)
    },
    async getCountTime({commit, state}, params) {
        return await api.mineBaseMsgApi(`${state.Host}/itfer-zbdk/rest/worker/getCountTime/${params.userId}/${params.XN}/${params.XQ}/${params.ZC}`)
    },
    /**
     * 变更签到状态
    */
    async updateSignStatus({commit, state}, params) {
        return await api.mineBaseMsgApi(`${state.Host}/itfer-zbdk/rest/admin/updateSignStatus/${params.user_id}/${params.plan_id}/${params.sign_status}`)
    }
}

export default actions
